Exploring Java 9 by Fu Cheng

Exploring Java 9 by Fu Cheng

Author:Fu Cheng
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


public ProcessHandle start() throws IOException {

final ProcessBuilder processBuilder = new ProcessBuilder("top")

.inheritIO();

return processBuilder.start().toHandle();

}

public void waitFor(final ProcessHandle processHandle) {

final CountDownLatch latch = new CountDownLatch(1);

processHandle.onExit().whenCompleteAsync((handle, throwable) -> {

if (throwable == null) {

System.out.println(handle.pid());

} else {

throwable.printStackTrace();

}

latch.countDown();

});

final Thread shutdownThread = new Thread(() -> {

try {

Thread.sleep(1000);

} catch (final InterruptedException e) {

e.printStackTrace();

}

if (processHandle.supportsNormalTermination()) {

processHandle.destroy();

} else {

processHandle.destroyForcibly();

}

});

shutdownThread.start();

try {

shutdownThread.join();

latch.await();

} catch (final InterruptedException e) {

e.printStackTrace();

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.